package com.linshengjian.snowball.core.controller;

import com.linshengjian.snowball.core.BaseModel;
import com.linshengjian.snowball.core.IReadService;
import com.linshengjian.snowball.core.exception.SystemErrorException;
import com.linshengjian.snowball.core.page.PageData;
import com.linshengjian.snowball.core.page.PageParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.io.Serializable;

public class BaseReadController<ID extends Serializable,M extends BaseModel<ID>, S extends IReadService<M, ID>> {

    @Autowired
    private S service;

    @ApiOperation("根据ID 获取详情")
    @GetMapping("{id}")
    public M get(@PathVariable ID id) throws SystemErrorException {
        return service.get(id);
    }

    @ApiOperation("分页查询")
    @GetMapping()
    public PageData<M> list(String keywords, PageParam pageReq) throws SystemErrorException, IllegalAccessException, InstantiationException {
        return service.list(keywords, pageReq);
    }
}
